package com.zhou.common.mybatis.template.shiro.zhou.filter;

import org.springframework.security.config.annotation.web.HttpSecurityBuilder;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy;

public final class UserCenterLoginConfigurer<H extends HttpSecurityBuilder<H>> extends AbstractHttpConfigurer<UserCenterLoginConfigurer<H>, H> {

    private UserCenterLoginFilter userCenterLoginFilter;

    public UserCenterLoginConfigurer() {
        this.userCenterLoginFilter=new UserCenterLoginFilter();
    }

    @Override
    public void configure(H http) throws Exception {
        SessionAuthenticationStrategy sessionAuthenticationStrategy = http
                .getSharedObject(SessionAuthenticationStrategy.class);
        if (sessionAuthenticationStrategy != null) {
            this.userCenterLoginFilter.setSessionStrategy(sessionAuthenticationStrategy);
        }
        RememberMeServices rememberMeServices = http.getSharedObject(RememberMeServices.class);
        UserCenterLoginFilter userCenterLoginFilter = postProcess(this.userCenterLoginFilter);
        http.addFilterBefore(userCenterLoginFilter, UsernamePasswordAuthenticationFilter.class);
    }

    @Override
    public H and() {
        return super.and();
    }
}
